﻿using System;
using System.Data;
using HRM.Common;

namespace HRM.BusinessLogic
{
    public class BhDetailInfo : Standard_Info
    {

        public BhDetailInfo()
        {
            //_Detail_Documentid = (Int64)Null.SetNullValue(_Detail_Documentid);
            //_Detail_Socialrate = (Decimal)Null.SetNullValue(_Detail_Socialrate);
            //_Detail_Medicalrate = (Decimal)Null.SetNullValue(_Detail_Medicalrate);
            //_Detail_Unemployedrate = (Decimal)Null.SetNullValue(_Detail_Unemployedrate);
            //_Detail_Newbasicfactor = (Decimal)Null.SetNullValue(_Detail_Newbasicfactor);
            //_Detail_Newpositionfactor = (Decimal)Null.SetNullValue(_Detail_Newpositionfactor);
            //_Detail_Newoverfactor = (Decimal)Null.SetNullValue(_Detail_Newoverfactor);
            //_Detail_Newjobfactor = (Decimal)Null.SetNullValue(_Detail_Newjobfactor);
            //_Detail_Newareafactor = (Decimal)Null.SetNullValue(_Detail_Newareafactor);
            //_Detail_Oldbasicfactor = (Decimal)Null.SetNullValue(_Detail_Oldbasicfactor);
            //_Detail_Oldpositionfactor = (Decimal)Null.SetNullValue(_Detail_Oldpositionfactor);
            //_Detail_Oldoverfactor = (Decimal)Null.SetNullValue(_Detail_Oldoverfactor);
            //_Detail_Oldjobfactor = (Decimal)Null.SetNullValue(_Detail_Oldjobfactor);
            //_Detail_Oldareafactor = (Decimal)Null.SetNullValue(_Detail_Oldareafactor);
            //_Detail_Newamount = (Decimal)Null.SetNullValue(_Detail_Newamount);
            //_Detail_Oldamount = (Decimal)Null.SetNullValue(_Detail_Oldamount);
            //_Detail_Status = (Int32)Null.SetNullValue(_Detail_Status);
            //_Detail_Totalmonth = (Int32)Null.SetNullValue(_Detail_Totalmonth);
            //_Detail_Basicsalary = (Decimal)Null.SetNullValue(_Detail_Basicsalary);
            //_Detail_Newoverfactor_Percent = (Int32)Null.SetNullValue(_Detail_Newoverfactor_Percent);
            //_Detail_Newjobfactor_Percent = (Int32)Null.SetNullValue(_Detail_Newjobfactor_Percent);
            //_Detail_Oldoverfactor_Percent = (Int32)Null.SetNullValue(_Detail_Oldoverfactor_Percent);
            //_Detail_Oldjobfactor_Percent = (Int32)Null.SetNullValue(_Detail_Oldjobfactor_Percent);
        }


        private Int64 _Detail_Id;
        public Int64 Detail_Id
        {
            get { return _Detail_Id; }
            set { _Detail_Id = value; }
        }

        private Int64 _Detail_Documentid;
        public Int64 Detail_Documentid
        {
            get { return _Detail_Documentid; }
            set { _Detail_Documentid = value; }
        }

        private String _Detail_Employeecode;
        public String Detail_Employeecode
        {
            get { return _Detail_Employeecode; }
            set { _Detail_Employeecode = value; }
        }

        private String _Detail_Insbookno;
        public String Detail_Insbookno
        {
            get { return _Detail_Insbookno; }
            set { _Detail_Insbookno = value; }
        }

        private DateTime _Detail_Fromdate;
        public DateTime Detail_Fromdate
        {
            get { return _Detail_Fromdate; }
            set { _Detail_Fromdate = value; }
        }

        private DateTime _Detail_Todate;
        public DateTime Detail_Todate
        {
            get { return _Detail_Todate; }
            set { _Detail_Todate = value; }
        }

        private String _Detail_Instypecode;
        public String Detail_Instypecode
        {
            get { return _Detail_Instypecode; }
            set { _Detail_Instypecode = value; }
        }

        private Decimal _Detail_Socialrate;
        public Decimal Detail_Socialrate
        {
            get { return _Detail_Socialrate; }
            set { _Detail_Socialrate = value; }
        }

        private Decimal _Detail_Medicalrate;
        public Decimal Detail_Medicalrate
        {
            get { return _Detail_Medicalrate; }
            set { _Detail_Medicalrate = value; }
        }

        private Decimal _Detail_Unemployedrate;
        public Decimal Detail_Unemployedrate
        {
            get { return _Detail_Unemployedrate; }
            set { _Detail_Unemployedrate = value; }
        }

        private Decimal _Detail_Newbasicfactor;
        public Decimal Detail_Newbasicfactor
        {
            get { return _Detail_Newbasicfactor; }
            set { _Detail_Newbasicfactor = value; }
        }

        private Decimal _Detail_Newpositionfactor;
        public Decimal Detail_Newpositionfactor
        {
            get { return _Detail_Newpositionfactor; }
            set { _Detail_Newpositionfactor = value; }
        }

        private Decimal _Detail_Newoverfactor;
        public Decimal Detail_Newoverfactor
        {
            get { return _Detail_Newoverfactor; }
            set { _Detail_Newoverfactor = value; }
        }

        private Decimal _Detail_Newjobfactor;
        public Decimal Detail_Newjobfactor
        {
            get { return _Detail_Newjobfactor; }
            set { _Detail_Newjobfactor = value; }
        }

        private Decimal _Detail_Newareafactor;
        public Decimal Detail_Newareafactor
        {
            get { return _Detail_Newareafactor; }
            set { _Detail_Newareafactor = value; }
        }

        private Decimal _Detail_Oldbasicfactor;
        public Decimal Detail_Oldbasicfactor
        {
            get { return _Detail_Oldbasicfactor; }
            set { _Detail_Oldbasicfactor = value; }
        }

        private Decimal _Detail_Oldpositionfactor;
        public Decimal Detail_Oldpositionfactor
        {
            get { return _Detail_Oldpositionfactor; }
            set { _Detail_Oldpositionfactor = value; }
        }

        private Decimal _Detail_Oldoverfactor;
        public Decimal Detail_Oldoverfactor
        {
            get { return _Detail_Oldoverfactor; }
            set { _Detail_Oldoverfactor = value; }
        }

        private Decimal _Detail_Oldjobfactor;
        public Decimal Detail_Oldjobfactor
        {
            get { return _Detail_Oldjobfactor; }
            set { _Detail_Oldjobfactor = value; }
        }

        private Decimal _Detail_Oldareafactor;
        public Decimal Detail_Oldareafactor
        {
            get { return _Detail_Oldareafactor; }
            set { _Detail_Oldareafactor = value; }
        }

        private Decimal _Detail_Newamount;
        public Decimal Detail_Newamount
        {
            get { return _Detail_Newamount; }
            set { _Detail_Newamount = value; }
        }

        private Decimal _Detail_Oldamount;
        public Decimal Detail_Oldamount
        {
            get { return _Detail_Oldamount; }
            set { _Detail_Oldamount = value; }
        }

        private String _Detail_Type;
        public String Detail_Type
        {
            get { return _Detail_Type; }
            set { _Detail_Type = value; }
        }

        private String _Detail_Regioncode;
        public String Detail_Regioncode
        {
            get { return _Detail_Regioncode; }
            set { _Detail_Regioncode = value; }
        }

        private String _Detail_Hospitalcode;
        public String Detail_Hospitalcode
        {
            get { return _Detail_Hospitalcode; }
            set { _Detail_Hospitalcode = value; }
        }

        private Boolean _Detail_Takecard;
        public Boolean Detail_Takecard
        {
            get { return _Detail_Takecard; }
            set { _Detail_Takecard = value; }
        }

        private Int32 _Detail_Status;
        public Int32 Detail_Status
        {
            get { return _Detail_Status; }
            set { _Detail_Status = value; }
        }

        private Int32 _Detail_Totalmonth;
        public Int32 Detail_Totalmonth
        {
            get { return _Detail_Totalmonth; }
            set { _Detail_Totalmonth = value; }
        }

        private Decimal _Detail_Basicsalary;
        public Decimal Detail_Basicsalary
        {
            get { return _Detail_Basicsalary; }
            set { _Detail_Basicsalary = value; }
        }

        private String _Detail_Description;
        public String Detail_Description
        {
            get { return _Detail_Description; }
            set { _Detail_Description = value; }
        }

        private Int32 _Detail_Newoverfactor_Percent;
        public Int32 Detail_Newoverfactor_Percent
        {
            get { return _Detail_Newoverfactor_Percent; }
            set { _Detail_Newoverfactor_Percent = value; }
        }

        private Int32 _Detail_Newjobfactor_Percent;
        public Int32 Detail_Newjobfactor_Percent
        {
            get { return _Detail_Newjobfactor_Percent; }
            set { _Detail_Newjobfactor_Percent = value; }
        }

        private Int32 _Detail_Oldoverfactor_Percent;
        public Int32 Detail_Oldoverfactor_Percent
        {
            get { return _Detail_Oldoverfactor_Percent; }
            set { _Detail_Oldoverfactor_Percent = value; }
        }

        private Int32 _Detail_Oldjobfactor_Percent;
        public Int32 Detail_Oldjobfactor_Percent
        {
            get { return _Detail_Oldjobfactor_Percent; }
            set { _Detail_Oldjobfactor_Percent = value; }
        }

        private String _Detail_PositionName;
        public String Detail_PositionName
        {
            get { return _Detail_PositionName; }
            set { _Detail_PositionName = value; }
        }
    }

    public class Detail_Controller : Standard_Controller
    {
        #region "Contructor"
        private static Detail_Controller _instance;
        protected Detail_Controller() { }
        protected new void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static Detail_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new Detail_Controller();
                }
            }
            return _instance;
        }
        public static Detail_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                Detail_Controller _instanceTrans = new Detail_Controller();
                _instanceTrans.Trans_Name = transName;
                return _instanceTrans;
            }
            else
                return Instance();
        }
        #endregion

        public const String cs_Table_Name = "";

        public int Header_Using(int DocumentID)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Using"), DocumentID));
        }

        public DataSet Header_GetAll()
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetAll"));
        }

        public DataSet Header_GetList(out int ItemCount, int currentPage, int pageSize, string _BranchCode, int _Month, int _Year, string _Type)
        {
            ItemCount = 0;
            DataSet ds= DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetList"), currentPage, pageSize, _BranchCode, _Month, _Year, _Type);
            if (ds != null && ds.Tables.Count > 0)
                ItemCount = Globals.Object_GetValue<int>(ds.Tables[1].Rows[0][0]);
            return ds;
        }

        public BhHeaderInfo Header_GetInfo(int HeaderID)
        {
            return CBO.FillObject<BhHeaderInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetInfo"), HeaderID));
        }

        public BhHeaderInfo Header_GetMaxBymonth(int _Month, int _Year, string _BranchCode, string _Type)
        {
            return CBO.FillObject<BhHeaderInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetMaxByMonth"), _Month, _Year, _BranchCode, _Type));
        }

        public int Header_Insert(BhHeaderInfo eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Insert"), eInfo.Document_Branchcode, eInfo.Document_Date, eInfo.Document_Month, eInfo.Document_Year, eInfo.Document_Period, eInfo.Document_Social, eInfo.Document_Medical, eInfo.Document_Unemployed, eInfo.Document_Basicsalary, eInfo.Document_Isinitial, eInfo.Document_Type));
        }

        public bool Header_Update(BhHeaderInfo eInfo)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Update"), eInfo.Document_Id, eInfo.Document_Branchcode, eInfo.Document_Date, eInfo.Document_Month, eInfo.Document_Year, eInfo.Document_Period, eInfo.Document_Social, eInfo.Document_Medical, eInfo.Document_Unemployed, eInfo.Document_Basicsalary, eInfo.Document_Isinitial, eInfo.Document_Type));
        }

        public bool Header_Delete(int DocumentID)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Delete"), DocumentID));
        }

        public bool Header_DeleteByPeriod(string BrandCode, int Year, int Month, int Period, string Type)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_DeleteByPeriod"), BrandCode, Year, Month, Period, Type));
        }

        public int Header_GetPreDocumentPeroid(string BrandCode, int Year, int Month, int Period, string Type)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetPreDocumentPeriod"), BrandCode, Year, Month, Period, Type));
        }

        public bool Header_Exist(int _ID, string BranchCode, DateTime _Date, string _SIBookNo, string _FromDate, string _ToDate, string _InsTypeCode)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Exist"), _ID, BranchCode, _Date, _SIBookNo, _FromDate, _ToDate, _InsTypeCode));
        }

        public bool Header_CheckExist(int _ID, string BranchCode, DateTime _Date, int _Month, int _Year, int _Period, string _Type)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_CheckExist"), _ID, BranchCode, _Date, _Month, _Year, _Period, _Type));
        }

        public int Detail_Using(int DetailID)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Using"), DetailID));
        }

        public DataSet Detail_GetAll()
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetAll"));
        }

        public DataSet Detail_GetList(out int ItemCount, int currentPage, int pageSize, int _DocumentID)
        {
            ItemCount = 0;
            DataSet ds = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetList"), currentPage, pageSize, _DocumentID);
            if (ds != null && ds.Tables.Count > 0)
                ItemCount = Globals.Object_GetValue<int>(ds.Tables[1].Rows[0][0]);
            return ds;
        }

        public DataSet Detail_GetBySIBookNo(string _SIBookNo, string _BranchCode, DateTime _Dateval)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetBySIBookNo"), _SIBookNo, _BranchCode, _Dateval);
        }

        public BhDetailInfo Detail_GetInfo(int DetailID)
        {
            return CBO.FillObject<BhDetailInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetInfo"), DetailID));
        }

        public BhDetailInfo Detail_CheckValid(string _InsBookNo, string InsType, string _BranchCode, DateTime _DateVal)
        {
            return CBO.FillObject<BhDetailInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_CheckValid"), _InsBookNo, InsType, _BranchCode, _DateVal));
        }

        public int Detail_Insert(BhDetailInfo eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Insert"), 
                
                eInfo.Detail_Documentid, 
                eInfo.Detail_Employeecode, 
                eInfo.Detail_Insbookno, 
                eInfo.Detail_Fromdate, 
                eInfo.Detail_Todate, 
                eInfo.Detail_Instypecode, 
                eInfo.Detail_Socialrate, 
                eInfo.Detail_Medicalrate, 
                eInfo.Detail_Unemployedrate, 
                eInfo.Detail_Newbasicfactor, 
                eInfo.Detail_Newpositionfactor, 
                eInfo.Detail_Newoverfactor,
                eInfo.Detail_Newjobfactor, 
                eInfo.Detail_Newareafactor, 
                eInfo.Detail_Oldbasicfactor, 
                eInfo.Detail_Oldpositionfactor, 
                eInfo.Detail_Oldoverfactor, 
                eInfo.Detail_Oldjobfactor, 
                eInfo.Detail_Oldareafactor, 
                eInfo.Detail_Regioncode, 
                eInfo.Detail_Hospitalcode, 
                eInfo.Detail_Newamount, 
                eInfo.Detail_Oldamount, 
                eInfo.Detail_Type, 
                eInfo.Detail_Takecard, 
                eInfo.Detail_Status, 
                eInfo.Detail_Totalmonth,
                eInfo.Detail_Description == null ? "" : eInfo.Detail_Description
                , eInfo.Detail_Oldoverfactor_Percent,
                eInfo.Detail_Oldjobfactor_Percent
                ,eInfo.Detail_Newoverfactor_Percent,
                eInfo.Detail_Newjobfactor_Percent,
                eInfo.Detail_PositionName == null ? "" : eInfo.Detail_PositionName
                ));
        }

        public bool Detail_Update(BhDetailInfo eInfo)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Update"), eInfo.Detail_Id, eInfo.Detail_Documentid, eInfo.Detail_Employeecode, eInfo.Detail_Insbookno, eInfo.Detail_Fromdate, eInfo.Detail_Todate, eInfo.Detail_Instypecode, eInfo.Detail_Socialrate, eInfo.Detail_Medicalrate, eInfo.Detail_Unemployedrate, eInfo.Detail_Newbasicfactor, eInfo.Detail_Newpositionfactor, eInfo.Detail_Newoverfactor, eInfo.Detail_Newjobfactor, eInfo.Detail_Newareafactor, eInfo.Detail_Oldbasicfactor, eInfo.Detail_Oldpositionfactor, eInfo.Detail_Oldoverfactor, eInfo.Detail_Oldjobfactor, eInfo.Detail_Oldareafactor, eInfo.Detail_Regioncode, eInfo.Detail_Hospitalcode, eInfo.Detail_Newamount, eInfo.Detail_Oldamount, eInfo.Detail_Type, eInfo.Detail_Takecard, eInfo.Detail_Status, eInfo.Detail_Totalmonth, eInfo.Detail_Description
                , eInfo.Detail_Oldoverfactor_Percent,eInfo.Detail_Oldjobfactor_Percent
                ,eInfo.Detail_Newoverfactor_Percent,eInfo.Detail_Newjobfactor_Percent,eInfo.Detail_PositionName));
        }

        public bool Detail_Delete(int DetailID, int _DocumentID)
        {
            return DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Delete"), DetailID, _DocumentID) > 0;
        }

        public bool Detail_Exist(int _ID, string _SIBookNo, DateTime _FromDate, DateTime _ToDate, string _InsTypeCode, Decimal OldAmount, Decimal OldBasicFactor, Decimal OldPositionFactor, Decimal OldOverFactor, Decimal OldJobFactor, Decimal NewAmount, Decimal NewBasicFactor, Decimal NewPositionFactor, Decimal NewOverFactor, Decimal NewJobFactor)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Exist"), _ID, _SIBookNo, _FromDate, _ToDate, _InsTypeCode, OldAmount, OldBasicFactor, OldJobFactor, OldOverFactor, OldPositionFactor, NewAmount, NewBasicFactor, NewJobFactor, NewOverFactor, NewPositionFactor));
        }

        public bool Detail_CheckExistSIBookNo(string _SIBookNo, string _BranchCode)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_CheckExistSIBookNo"), _SIBookNo, _BranchCode));
        }

        public DataSet Detail_Mau03_Excel(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Form03_Excel"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau02_Excel(int period, int month, int year, string BranchCode, bool _IsAll)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Form02_Excel_TEST"), month, year, period, BranchCode, _IsAll);
        }

        public DataSet Detail_Mau02_TCT_Excel(int period, int month, int year, string BranchCode, bool _IsAll)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Form02_TCT_Excel"), month, year, period, BranchCode, _IsAll);
        }

        public DataSet Detail_Mau03_TangMoi(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_TangMoi"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03Giam(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_Giam"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03DCLuong(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_DCLuong"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03BoSungBHTN(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_BoSungBHTN"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03BoSungBHYT(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_BoSungBHYT"), month, year, period, BranchCode);
        }

        public DataSet Detail_TongHopMau03(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_TongHopMau03"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03CuoiKy(int period, int month, int year, string BranchCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_GetForForm03_TongHopCuoiKy"), month, year, period, BranchCode);
        }

        public DataSet Detail_Mau03_TangMoi_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_TangMoi_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_Mau03Giam_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_Giam_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_Mau03DCLuong_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_DCLuong_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_Mau03BoSungBHTN_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_BoSungBHTN_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_Mau03BoSungBHYT_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_Form03_BoSungBHYT_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_TongHopMau03_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_TongHopMau03_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_Mau03CuoiKy_TEST(int period, int month, int year, string BranchCode, string TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_GetForForm03_TongHopCuoiKy_TEST"), month, year, period, BranchCode, TypeCode);
        }

        public DataSet Detail_TongHopMau02(int period, int month, int year, string BranchCode, bool _IsAll)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_TongHopMau02"), month, year, period, BranchCode, _IsAll);
        }

        public DataSet Detail_GetForForm02(int period, int _month, int _year, string BranchCode, bool _IsAll)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_GetForForm02"), _month, _year, period, BranchCode, _IsAll);
        }

        public DataSet Detail_TongHopMau02_TEST(int period, int month, int year, string BranchCode, bool _IsAll, string _TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_TongHopMau02_TEST"), month, year, period, BranchCode, _IsAll, _TypeCode);
        }

        public DataSet Detail_GetForForm02_TEST(int period, int _month, int _year, string BranchCode, bool _IsAll, string _TypeCode)
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_BaoHiem_GetForForm02_TEST"), _month, _year, period, BranchCode, _IsAll, _TypeCode);
        }

        public bool KiemTraGiaTriThangPhatSinh(string Detail_InsBookNo, DateTime Detail_ToDate)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_KiemTraGiaTriThangPhatSinh"), Detail_InsBookNo, Detail_ToDate));
        }

        public string GetLastestHSML(string Detail_InsBookNo, out DateTime ToDate)
        {
            //if (rdr["Detail_Type"] != DBNull.Value)
            //    retVal = (string)rdr["Detail_Type"];
            //if (rdr["Detail_ToDate"] != DBNull.Value)
            //    ToDate = (DateTime)rdr["Detail_ToDate"];

            ToDate = DateTime.MinValue;
            string retVal = "";
            //
            DataSet ds = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetLastestHSML"), Detail_InsBookNo);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                retVal = Globals.DB_GetValue<string>(ds.Tables[0].Rows[0]["Detail_Type"]);
                ToDate = Globals.DB_GetValue<DateTime>(ds.Tables[0].Rows[0]["Detail_ToDate"]);
            }
            return retVal;
        }

        public bool HasWarningTS(int branch_ID)
        {
            return Globals.Object_GetValue<Int32>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Employee_CoNghiThaiSan"), branch_ID)) > 0;
        }

        /// <summary>
        /// Lấy chức danh gần nhất theo tham số từ ngày -> đến ngày
        /// Nếu chức danh không có bên phát sinh bảo hiểm thì lấy bên hồ sơ nhân sự
        /// //Do SMS dùng font TCVN, nên cần convert sang Unicode
        /// </summary>
        /// <param name="_fromDate"></param>
        /// <param name="_toDate"></param>
        /// <param name="SoBH"></param>
        /// <param name="MaDV"></param>
        /// <param name="Employee_ID"></param>
        /// <returns></returns>
        public string GetPositionName(DateTime _fromDate, DateTime _toDate, string SoBH, string MaDV, int Employee_ID)
        {
            string sPosName = Globals.Object_GetValue<String>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_GetPositionName"), _fromDate, _toDate, SoBH, MaDV, Employee_ID));
            return sPosName;//.TcvnToUnicode();
        }


        public DataTable DSKhongThamGiaBH(string strBranchCode)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_DanhSachChotSo",false), strBranchCode);
        }

        public DataTable DSThamGiaBH(string strBranchCode, string sType, int departmentId, int PageIndex, int PageSize, string PageOrder)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_DanhSachThamGiaBH", false), 
                strBranchCode, 
                sType, 
                departmentId,
                PageIndex,
                PageSize,
                PageOrder
            );
        }

        public DataTable Detail_Get4TK01(int iKy, int iThang, int iNam, int iBranchId)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Get4TK01"), iKy, iThang, iNam, iBranchId);
        }

        public DataTable Get4D02TSImportSMS(int iPeriod, int iMonth, int iYear, string sBranchCode)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Detail_Get4D02TSImportSMS"), iPeriod,iMonth, iYear, sBranchCode);
        }
    }
}
